from __future__ import absolute_import, division

from gui.panda.base import *


class PandaSelectedPanel(PandaUIElement):
    texture_name =_ ('UI Details Panel')
    
    heading = Attribute()
    status  = Attribute()
    state   = Attribute()
    debug   = Attribute()
    
    def setup_element(self):
        self.heading = self.add_child(Heading('panel.selected.heading', ( 20, 20), text_align = '<', font_size = 16))
        self.status  = self.add_child(Label  ('panel.selected.status',  ( 32, 42), text_align = '<', font_size = 14))
        self.state   = self.add_child(Label  ('panel.selected.state',   ( 16, 70), text_align = '<', font_size = 14))
        self.debug   = self.add_child(Tooltip('panel.selected.debug',   (280, 70), text_align = '<', font_size = 11))
    
    def on_update(self):
        if self.model.has_building:
            self.show()
        else:
            self.hide()
            return
        
        self.heading.icon = self.model.building.name
        self.heading.text = self.model.building.name
        self.status .text = str(self.model.building.efficiency)
        self.state  .text = '\n'.join(sorted('%s:\n%s\n' % (k, v()) for k, v in self.model.building.state   .items()))
        self.debug  .text = '\n'.join(sorted('%s: %s' % item for item in self.model.building.__dict__.items()))
